package io.task.cc.message.socket;


import lombok.Getter;
import lombok.Setter;
import lombok.extern.slf4j.Slf4j;

import java.util.Objects;

@Slf4j
@Setter
@Getter
public class Node implements Comparable<Node> {
    private String ip;
    private int port;


    public Node(String ip, int port) {
        super();

        this.setIp(ip);
        this.setPort(port);
    }


    @Override
    public boolean equals(Object obj) {
        if (obj == null) {
            return false;
        }
        Node other = (Node) obj;
        return ip.equals(other.getIp()) && port == other.getPort();
    }


    @Override
    public int hashCode() {
        return (ip + ":" + port).hashCode();
    }

    @Override
    public int compareTo(Node other) {
        if (other == null) {
            return -1;
        }
        if (Objects.equals(ip, other.getIp()) && Objects.equals(port, other.getPort())) {
            return 0;
        } else {
            return this.toString().compareTo(other.toString());
        }
    }
}
